from rest_framework import serializers

from user.models import User


class UserListSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ["id","username","mobile","email","password"]
        # 防止密码泄露
        extra_kwargs={
            "password":{
                'write_only':True
            }
        }

    # 重写create方法
    def create(self, validated_data):
        return User.objects.create_user(**validated_data)
